import java.util.*;

class Solution {
    /*public int lengthOfLongestSubstring(String s) {
        Queue<Character> queue = new LinkedList<>();
        HashMap<Character, Integer> map = new HashMap<>();
        int res = 0;
        int start = 0;
        char[] arr = s.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            char c = arr[i];
            Integer repeatedIndex = map.get(c);
            if (repeatedIndex != null && repeatedIndex >= start) {
                for (int j = start; j <= repeatedIndex; j++) {
                    queue.poll();
                }
                start = repeatedIndex + 1;
            }
            map.put(c, i);
            queue.add(c);
            res = Math.max(res, queue.size());
            System.out.println(queue + " start:" + start + " i: " + i + " repeatedIndex: " + repeatedIndex);
        }
        return res;
    }*/
    public int lengthOfLongestSubstring(String s) {
        HashMap<Character, Integer> map = new HashMap<>();
        char[] arr = s.toCharArray();
        int res = 0;
        int start = 0;
        for (int i = 0; i < arr.length; i++) {
            char c = arr[i];
            Integer repeatedIndex = map.get(c);
            if (repeatedIndex != null && repeatedIndex >= start) {
                start = repeatedIndex + 1;
            }
            map.put(c, i);
            res = Math.max(res, i - start + 1);
            System.out.println("start:" + start + " i: " + i + " repeatedIndex: " + repeatedIndex);
        }
        return res;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        //int res = s.lengthOfLongestSubstring("uwekuaxt");
        int res = s.lengthOfLongestSubstring("wsslpluuwekuaxt");
        //int res = s.lengthOfLongestSubstring("abcabcbb");
        System.out.println(res);
    }
}